package org.zjt.thread;

public class ThreadInterrupted {
    /**
     * 给系统线程发送一个中断指令，然后在线程中可以对该指令响应，做策略动作。
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() ->{
            for(;;){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("异常 线程中断");
                    return;
                }
                if(Thread.currentThread().isInterrupted()){
                    System.out.println("over 线程中断");
                    return;
                }
            }
        });
        t.start();
        t.interrupt();
        t.join(); // 等待t线程结束
        System.out.println("end");
    }
}
